package com.eurobcoin.helper;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;


public class NumberHelper {

	public static long stringToLong(String number, int decimals, Locale locale) throws ParseException {
		
		NumberFormat format = NumberFormat.getInstance(locale);
		Number nNumber = format.parse(number);
		double d = nNumber.doubleValue();
		double factor = Math.pow(10, (double)decimals);
		
		double dRet = d * factor;
		
		long ret = Math.round(dRet);
		
		return ret;
	}
	
	public static String longToDoubledString(long number, int decimals, Locale locale) {
		
		NumberFormat format = NumberFormat.getInstance(locale);
		format.setMinimumFractionDigits(decimals);
		format.setMaximumFractionDigits(decimals);
		
		double factor = Math.pow(10, (double)decimals);
		double d = (double)number / factor;
		
		String ret = format.format(d);
		
		return ret;
	}
	
	public static double longToDouble(long number, int decimals) {
		double factor = Math.pow(10, (double)decimals);
		double d = (double)number / factor;
		
		return d;
	}

}
